/* Reset and base styles optimized for iframe and mobile-first design */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    overflow: hidden;
    touch-action: manipulation;
}

/* Main container with responsive height handling */
.container {
    width: 100%;
    height: 450px; /* Default iframe height */
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Detect if running in new tab vs iframe */
@media (min-height: 500px) {
    .container {
        height: 90vh;
    }
}

/* Game area taking most of the vertical space */
.game-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    border-radius: 8px 8px 0 0;
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.1);
}

/* Street view with dynamic backgrounds */
.street-view {
    width: 100%;
    height: 100%;
    position: relative;
    background: linear-gradient(to bottom, #87CEEB 0%, #98FB98 70%, #90EE90 100%);
    transition: background 0.5s ease;
}

.background {
    width: 100%;
    height: 100%;
    position: absolute;
    background-size: cover;
    background-position: center;
    transition: all 0.5s ease;
}

/* Character sprite with smooth movement */
.character {
    position: absolute;
    bottom: 20%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2.5rem;
    transition: all 0.3s ease;
    z-index: 10;
}

/* Sign container for traffic signs */
.sign-container {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.traffic-sign {
    position: absolute;
    width: 60px;
    height: 60px;
    background: white;
    border: 3px solid #333;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    cursor: pointer;
    pointer-events: auto;
    transition: all 0.2s ease;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.traffic-sign:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

/* Sign identification popup with mobile-optimized touch targets */
.sign-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    z-index: 100;
    max-width: 90%;
    text-align: center;
}

.sign-image {
    width: 80px;
    height: 80px;
    margin: 0 auto 15px;
    background: #f5f5f5;
    border: 2px solid #ddd;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
}

.question {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 15px;
}

.choices {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.choice-btn {
    background: #2196F3;
    color: white;
    border: none;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px; /* Touch-friendly minimum */
    white-space: nowrap;
}

.choice-btn:hover {
    background: #1976D2;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.choice-btn:active {
    transform: translateY(0);
}

/* Control panel optimized for limited height */
.control-panel {
    height: 120px;
    background: white;
    border-top: 2px solid #e0e0e0;
    display: flex;
    padding: 8px;
    gap: 8px;
}

/* Movement controls with touch-optimized buttons and new layout for down button */
.movement-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 100px; /* Increased width to accommodate horizontal controls */
}

/* New horizontal controls container for left, down, and right buttons */
.horizontal-controls {
    display: flex;
    gap: 4px;
    align-items: center;
}

.direction-btn {
    width: 44px;
    height: 32px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.direction-btn:hover {
    background: #45a049;
    transform: scale(1.05);
}

.direction-btn:active {
    transform: scale(0.95);
}

/* Progress section with compact layout */
.progress-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Safety score meter */
.score-meter {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
}

.meter-label {
    font-weight: 600;
    color: #333;
    min-width: 60px;
}

.meter-bar {
    flex: 1;
    height: 20px;
    background: #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.meter-fill {
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #8BC34A);
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 10px;
}

.score-text {
    font-weight: 600;
    color: #333;
    min-width: 40px;
}

/* Badge collection display */
.badge-collection {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
}

.badge-label {
    font-weight: 600;
    color: #333;
    min-width: 60px;
}

.badges {
    display: flex;
    gap: 6px;
}

.badge {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.badge.locked {
    background: #f5f5f5;
    opacity: 0.5;
    filter: grayscale(100%);
}

.badge.earned {
    background: #FFD700;
    border-color: #FFA000;
    animation: badgeEarn 0.5s ease;
}

@keyframes badgeEarn {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* Neighborhood map */
.neighborhood-map {
    min-width: 120px;
    font-size: 0.75rem;
}

.map-label {
    font-weight: 600;
    color: #333;
    margin-bottom: 6px;
    text-align: center;
}

.map-areas {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.area {
    padding: 4px 8px;
    border-radius: 4px;
    text-align: center;
    font-weight: 500;
    transition: all 0.2s ease;
    cursor: pointer;
}

.area.active {
    background: #4CAF50;
    color: white;
}

.area.completed {
    background: #2196F3;
    color: white;
}

.area.locked {
    background: #f5f5f5;
    color: #999;
    cursor: not-allowed;
}

/* Feedback overlay */
.feedback {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    z-index: 200;
}

.feedback-icon {
    font-size: 3rem;
    margin-bottom: 10px;
}

.feedback-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
}

.feedback.correct .feedback-icon {
    color: #4CAF50;
}

.feedback.incorrect .feedback-icon {
    color: #f44336;
}

/* Celebration animation */
.celebration {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255,215,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.celebration-text {
    font-size: 2rem;
    font-weight: bold;
    color: #333;
    text-align: center;
    animation: celebrate 2s ease-in-out;
}

@keyframes celebrate {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Mobile responsiveness for smaller screens */
@media (max-width: 480px) {
    .control-panel {
        height: 100px;
        padding: 6px;
    }
    
    .movement-controls {
        min-width: 90px; /* Adjusted for mobile */
    }
    
    .direction-btn {
        width: 36px;
        height: 28px;
        font-size: 1rem;
    }
    
    .badge {
        width: 28px;
        height: 28px;
        font-size: 1rem;
    }
    
    .choice-btn {
        padding: 10px 12px;
        font-size: 0.8rem;
    }
    
    .sign-popup {
        padding: 15px;
    }
    
    .sign-image {
        width: 60px;
        height: 60px;
        font-size: 2rem;
    }
}